from datetime import datetime, timedelta


def if_runnian(y):

    return y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)


def next_brithday(today, m, d):

    y = today.year
    next_brithday = datetime(y, m, d)

    if next_brithday.date() < today or (m == 2 and d == 29 and not is_leap(y)):
        y += 1
        next_brithday = datetime(y, m, d)

        if m == 2 and d == 29 and not if_runnian(y):
            next_brithday = datetime(y, 2, 28)

    return next_brithday.date()


try:
    today = datetime.now().date()

    brithday_str = input("请输入生日（格式：月-日，如05-20）：")
    m, d = map(int, brithday_str.split('-'))

    if not (1 <= m <= 12):
        raise ValueError("月份需在1-12之间")

    if m == 2 and d == 29:
        pass
    else:
        try:
            datetime(2024, m, d)
        except ValueError:
            raise ValueError("无效日期")

    next_brirhday = next_brithday(today, m, d)
    days_left = (next_brirhday - today).days

    print(f"距离您的下一个生日还有 {days_left} 天！")

except ValueError as e:
    print(f"输入错误：{e}")
except Exception as e:
    print(f"发生错误：{e}")